package com.graduate.examapp.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.graduate.examapp.R
import com.graduate.examapp.entity.ExamTask

/**
 * Author: etacao
 * Date: 2023/5/9 16:07
 * Description:
 * History:
 * <author> <time> <version> <desc>
 * etacao 2023/5/9 1.0 首次创建
 */
class HomeExamTaskAdapter: RecyclerView.Adapter<HomeExamTaskAdapter.ExamTaskHolder>() {
    var dataSource: MutableList<ExamTask> = ArrayList()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExamTaskHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.home_exam_task_item, parent, false)
        return ExamTaskHolder(view)
    }

    override fun onBindViewHolder(holder: ExamTaskHolder, i: Int) {
        val dataText = StringBuilder()
        val examTask = dataSource[i]
        //构建 dataText
        dataText.append("课程名称: ${examTask.courseName}\n")
            .append("考试时间：${examTask.examDate} ")
            .append(examTask.weekDay)
            .append(" ")
            .append(examTask.duration)
            .append("\n")
            .append("地点：${examTask.place}\n")
            .append("主监考教师：${examTask.invigilatorName}\n")
            .append("副监考教师：${examTask.assistantName}")

        holder.examTaskText.text = dataText.toString()
    }

    override fun getItemCount(): Int {
        return dataSource.size
    }

    class ExamTaskHolder(taskItemView: View) : RecyclerView.ViewHolder(taskItemView) {
        val examTaskText = taskItemView.findViewById<TextView>(R.id.home_exam_text)
    }
}